import { getSession, setSession } from '@/utils/session'
export default {
	data() {
		return {
			homeConfig: [],
			searchLibraryList: [],
			searchLeftFileData: [],
		}
	},
	mounted() {
		this.homeConfig = JSON.parse(this.getSession('homeConfig')) || []
		this.init()
		this.searchLibraryList = [
			{ id: '1', name: this.showModuleName('kck') || '课程库', },
			{ id: '2', name: this.showModuleName('zyk') || '专业库', },
			{ id: '3', name: this.showModuleName('bzk') || '兵种库', },
			{ id: '4', name: this.showModuleName('ztk') || '专题库', },
			{ id: '5', name: this.showModuleName('sfwsp') || '示范微视频', },
			{ id: '6', name: this.showModuleName('pxzy') || '培训资源', },
		]
		this.searchLeftFileData = [
			{ label: '全部', value: '0', },
			{ label: this.showModuleName('text') || '文本', value: '1', },
			{ label: this.showModuleName('img') || '图片', value: '2', },
			{ label: this.showModuleName('video') || '视频', value: '3', },
		]
	},
	methods: {
		async init() {
			if (this.homeConfig.length) return
			let obj = { page: 1, limit: 999 }
			let res = await this.$store.dispatch('queryOpenApiSysColumnControl', obj)
			this.homeConfig = res.data
			setSession('homeConfig', JSON.stringify(res.data))
		},
		//模块是否显示
		showModuleObj(code) {
			let res = this.homeConfig.filter((v) => v.code == code)
			return res.length ? res[0] : {}
		},
		//模块是否显示
		showModule(code) {
			let res = this.homeConfig.filter((v) => v.code == code)
			return res.length ? res[0].isShow == 0 : true
		},
		//显示模块名字
		showModuleName(code) {
			let res = this.homeConfig.filter((v) => v.code == code)
			return res.length ? res[0].name : ''
		},
		//显示模块英文名字
		showModuleEnName(code) {
			let res = this.homeConfig.filter((v) => v.code == code)
			return res.length ? res[0].field4 : ''
		},
		//显示模块二级标题
		showModuleSubTitle(code) {
			let res = this.homeConfig.filter((v) => v.code == code)
			return res.length ? res[0].field1 : ''
		},
	},
}